﻿<UserControl x:Class="WeatherFrame.LocationListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
             xmlns:my="clr-namespace:WeatherFrame"
    mc:Ignorable="d"              Name="Root"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}" Width="800" Height="480"
    d:DesignHeight="480" d:DesignWidth="800">
    <UserControl.Resources>
        <ControlTemplate x:Key="RoundButton" TargetType="ButtonBase">
            <Border Padding="{StaticResource PhoneTouchTargetOverhang}" Margin="0,0,4,0" Background="#01000000">
            <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
                                        Background="{TemplateBinding Background}" CornerRadius="24" 
                     Height="48">
                <ContentControl x:Name="ContentContainer" Content="{TemplateBinding Content}"/>
            </Border>
            </Border>
        </ControlTemplate>
            <my:VisConverter x:Key="VisConverter"/>
        <my:EqualityConverter x:Key="EqualityConverter"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>            
        </Grid.RowDefinitions>
        <Grid Width="760" HorizontalAlignment="Left">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <!--<my:HighVisTextBlock Margin="40,5,10,5" VerticalAlignment="Top" Tag="where?"
                               FontSize="60"/>-->
            <TextBlock Margin="42,7,12,7" VerticalAlignment="Top" Text="where?"
                               FontSize="60"/>
            <Button Name="AddButton" Grid.Column="1" Template="{StaticResource RoundButton}" VerticalAlignment="Bottom" Margin="20,0,0,5" Click="Button_Click"
                                >
                <!--Visibility="{Binding Visibility,ElementName=EditDone}"-->
                <Image Source="../Icons/appbar.add.rest.png"/>
            </Button>
            <ToggleButton Grid.Column="2"  Template="{StaticResource RoundButton}" VerticalAlignment="Bottom" Margin="0,0,0,5"
                          IsChecked="{Binding IsEditingLocations,Mode=TwoWay}"
                                      Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked">
                <Grid>
                    <Image Source="../Icons/appbar.edit.rest.png" Name="EditIcon"/>
                    <TextBlock Name="EditDone" Visibility="Collapsed" Padding="5,0">done</TextBlock>
                </Grid>
            </ToggleButton>
            <Button Name="UnitsButton" Grid.Column="3" Template="{StaticResource RoundButton}" 
                    VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="20,0,0,5" Click="Unit_Click">
                <Grid>
                <TextBlock Visibility="{Binding UseCelsius,Converter={StaticResource VisConverter}}" Padding="8,0">°C</TextBlock>
                <TextBlock Visibility="{Binding UseCelsius,Converter={StaticResource VisConverter},ConverterParameter=False}" 
                           Padding="10,0">°F</TextBlock>
                </Grid>
            </Button>
            <Button Name="InfoButton" Grid.Column="4" Template="{StaticResource RoundButton}" VerticalAlignment="Bottom" Margin="0,0,0,5" Click="Info_Click"
                                >
                <Image Source="../Icons/appbar.questionmark.rest.png"/>
            </Button>
            <Grid Grid.Row="1" Grid.ColumnSpan="5"  Visibility="{Binding LocationState,Converter={StaticResource VisConverter},ConverterParameter=!Normal}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBox  Name="LocationTextBox"  FontSize="48" Margin="52,0,0,0"
                                 KeyDown="TextBox_KeyDown" InputScope="Search"
                                      TextChanged="LocationTextBox_TextChanged"
                          IsReadOnly="{Binding LocationState,Converter={StaticResource EqualityConverter},ConverterParameter=Searching}"/>
                <TextBlock IsHitTestVisible="False" Name="LocationTextBoxHint" Text="enter city name" Foreground="#BBBBBB"  FontSize="48" Margin="70,0,0,0" VerticalAlignment="Center"/>
                <Button Grid.Column="1"  Template="{StaticResource RoundButton}" VerticalAlignment="Center" Margin="0,0,0,5" Name="CancelButton" Click="Cancel_Click"
                        Visibility="{Binding LocationState,Converter={StaticResource VisConverter},ConverterParameter=!Searching}"
                                      >
                    <TextBlock Padding="5,0">cancel</TextBlock>
                </Button>                
                <ProgressBar Margin="52,14,0,0" IsIndeterminate="True" Visibility="{Binding LocationState,Converter={StaticResource VisConverter},ConverterParameter=Searching}" VerticalAlignment="Top"/>
            </Grid>
            <Grid Grid.Row="2" Grid.ColumnSpan="4" Margin="72,0,0,0" Height="280" Visibility="{Binding LocationState,Converter={StaticResource VisConverter},ConverterParameter=SearchResults}">
                <ListBox Name="SearchResultsList" ItemsSource="{Binding SearchResults}" FontSize="40" SelectionChanged="SearchResultSelected">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="HorizontalAlignment" Value="Left"/>
                        </Style>
                    </ListBox.ItemContainerStyle>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock FontSize="40" Text="{Binding Name}" Margin="0,0,10,0"/>
                                <TextBlock FontSize="24" Text="{Binding Details}" VerticalAlignment="Bottom" Opacity="0.7" Margin="0,0,0,7"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <TextBlock Name="NothingFound" FontSize="24" Visibility="{Binding SearchResults.Count,Converter={StaticResource VisConverter},ConverterParameter=0}">No locations found.</TextBlock>
            </Grid>
        </Grid>

        <Grid Grid.Row="1" Visibility="{Binding IsEditingLocations,Converter={StaticResource VisConverter}}">
            <CheckBox HorizontalAlignment="Left" IsChecked="{Binding AllowAccessToLocation,Mode=TwoWay}" Content="Allow use of my location" Margin="60,-5,0,-5"/>
        </Grid>
        <controls:PanoramaItem Margin="0,0,0,10" Grid.Row="2">
            <controls:PanoramaItem.HeaderTemplate>
                <DataTemplate>
                    <Grid/>
                </DataTemplate>
            </controls:PanoramaItem.HeaderTemplate>
        <ListBox  Foreground="LightGray" Name="LocationListBox" ItemsSource="{Binding Locations}" Margin="60,-30,4,0" SelectedItem="{Binding SelectedLocation, Mode=TwoWay}"
                  FontSize="48" SelectionMode="Single">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalAlignment" Value="Left"/>
                    </Style>
                </ListBox.ItemContainerStyle>
                    <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <!--<Grid Width="56">
                            <Border  Visibility="{Binding IsWaitingForWeather,Converter={StaticResource VisConverter}}"  VerticalAlignment="Bottom" Margin="0,0,0,-4">
                            <my:WeatherIcon DataContext="Sun" Width="56" Height="56"
                                            Loaded="WeatherIcon_Loaded">
                                <my:WeatherIcon.RenderTransform>
                                    <RotateTransform CenterX="28" CenterY="28"/>
                                </my:WeatherIcon.RenderTransform>
                            </my:WeatherIcon>
                                </Border>
                            </Grid>-->
                            <TextBlock Text="{Binding}"/>
                            <Border BorderThickness="0" Visibility="{Binding IsHere,Converter={StaticResource VisConverter},ConverterParameter=False}">
                            <Button Template="{StaticResource RoundButton}" Visibility="{Binding Tag,ElementName=Root}"
                                    Margin="0,0,0,-10" Click="Delete_Click">
                                <Image Source="../Icons/appbar.delete.rest.png"/>
                                </Button>
                            </Border>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </controls:PanoramaItem>
        <Button Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="14" BorderThickness="0" Padding="0" Margin="0"
                   Opacity="0.8" Foreground="LightGray" Click="WorldWeatherOnline_Click">
            <Button.Template>
                <ControlTemplate>
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
                                        Background="{TemplateBinding Background}"
                                        Margin="{StaticResource PhoneTouchTargetOverhang}"
                    >
                        <ContentControl x:Name="ContentContainer" Content="{TemplateBinding Content}"/>
                    </Border>
                </ControlTemplate>
            </Button.Template>

            <TextBlock>Powered by <Run TextDecorations="Underline">World Weather Online</Run></TextBlock>
        </Button>
        <my:InfoPage x:Name="InfoPanel" Visibility="{Binding ShowInfo,Converter={StaticResource VisConverter}}"/>
    </Grid>
</UserControl>
